
public class GoodHours {
    public static int howMany(String beforeTime,String afterTime){
    	int ans=0;
    	int startinghour=Integer.parseInt(beforeTime.substring(0,2));
    	int startingminute=Integer.parseInt(beforeTime.substring(3,5));
    	int endinghour=Integer.parseInt(afterTime.substring(0,2));
    	int endingminute=Integer.parseInt(afterTime.substring(3,5));
    	int currenthour=startinghour;
    	int currentminute=startingminute;
    	while(currentminute!=endingminute || currenthour!=endinghour){
    		//H & HMM
    		if((currenthour/10)==(currenthour%10)*(currentminute/10)*(currentminute%10)){
    			ans++;
    			if(currentminute==59 && currenthour!=23){currentminute=0;currenthour++;continue;}
    			else if(currenthour==23 && currentminute==59){currentminute=0;currenthour=0;continue;}
    			else {currentminute++;continue;}
    		}
    		//HH && MM
    		else if((currenthour/10)*(currenthour%10)==(currentminute/10)*(currentminute%10)){
    			ans++;
    			if(currentminute==59 && currenthour!=23){currentminute=0;currenthour++;continue;}
    			else if(currenthour==23 && currentminute==59){currentminute=0;currenthour=0;continue;}
    			else {currentminute++;continue;}
    		}
    		//HHM & M
    		else if((currenthour/10)*(currenthour%10)*(currentminute/10)==(currentminute%10)){
    			ans++;
    			if(currentminute==59 && currenthour!=23){currentminute=0;currenthour++;continue;}
    			else if(currenthour==23 && currentminute==59){currentminute=0;currenthour=0;continue;}
    			else {currentminute++;continue;}
    		}
    		else{
    			if(currentminute==59 && currenthour!=23){currentminute=0;currenthour++;continue;}
    			else if(currenthour==23 && currentminute==59){currentminute=0;currenthour=0;continue;}
    			else {currentminute++;continue;}
    		}
    	}
    	//H & HMM
		if((currenthour/10)==(currenthour%10)*(currentminute/10)*(currentminute%10)){
			ans++;
		}
		//HH && MM
		else if((currenthour/10)*(currenthour%10)==(currentminute/10)*(currentminute%10)){
			ans++;
		}
		//HHM & M
		else if((currenthour/10)*(currenthour%10)*(currentminute/10)==(currentminute%10)){
			ans++;
		}
    	return ans;
    }
	public static void main(String[] args) {
		 System.out.println(howMany("00:56","12:32"));
         System.exit(0);
	}

}
